<?php

use Illuminate\Database\Seeder;
use App\Permission;
use App\Role;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //查找角色
        $admin = Role::where('display_name','admin')->first();
        $user  = Role::where('display_name','user') ->first();
        //将权限付给不同的角色
        $permissions = Permission::all();

        //把所有权限都付给超级管理员
        foreach($permissions as $permission){
        	$admin -> attachPermission($permission);
        }

        //把后台登陆,后台首页,游客列表付给普通管理员
        $login = Permission::where('name','system.login')->first();
        $index = Permission::where('name','system.index')->first();
        $guest = Permission::where('name','guest.list')->first();

        $user->attachPermissions(array($login,$index,$guest));
        }
}
